<template>
  <el-dialog
    :close-on-click-modal="false"
    width="45%"
    :title="title"
    :visible.sync="visible"
    :before-close="close"
    lock-scroll
    append-to-body
  >
    <el-form
      status-icon
      :rules="rules"
      :model="datas"
      @keyup.enter.native="save"
      ref="editForm"
    >
      <el-row :gutter="10">
        <el-col :span="23">
          <el-form-item
            prop="policyname"
            label="规则名称"
            :label-width="baseStyle.width"
          >
            <el-input
              v-model="datas.policyname"
              :readonly="false"
              autocomplete="off"
            ></el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="23">
          <el-form-item
            prop="classic"
            label="类型"
            :label-width="baseStyle.width"
          >
            <el-select
              v-model="datas.classic"
              placeholder="请选择"
              style="width: 100%"
            >
              <el-option
                v-for="item in classicList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="23">
          <el-form-item
            prop="status"
            label="是否禁用"
            :label-width="baseStyle.width"
          >
            <el-radio-group v-model="datas.status">
              <el-radio :label="1">启用</el-radio>
              <el-radio :label="0">禁用</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col> -->
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button :type="'primary'" :loading="loading" @click.native="save()"
        >保存</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import { Message } from "element-ui";

export default {
  name: "ClassicForm",
  props: {
    visible: Boolean,
    baseStyle: Object,
    title: String,
    datas: {
      type: Object,
      default: function () {
        return { policyname: "" };
      },
    },
    saveForm: Function,
  },
  data() {
    const rules = this.getRules();
    return {
      loading: false,
      rules,
      classicList: [
        { id: 1, name: "菜单" },
        { id: 2, name: "按钮" },
        { id: 3, name: "编辑" },
        { id: 4, name: "删除" },
      ],
    };
  },
  computed: {},
  created() {},
  methods: {
    cancel() {
      this.loading = false;
      this.$emit("update:visible", false);
      this.$refs.editForm.resetFields();
    },
    close() {
      this.cancel();
    },
    save() {
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          this.loading = true;
          this.$emit("saveForm", { ...this.datas });
          // this.cancel();
        } else {
          return false;
        }
      });
    },
    getRules() {
      return {
        policyname: [
          {
            validator: (rule, value, callback) => {
              if (!this.datas.policyname) {
                callback(new Error(`请填写类别名称`));
                return;
              }
              if (this.datas.policyname.trim().length < 1) {
                callback(new Error(`请填写类别名称`));
                return;
              }
              callback();
            },
            trigger: "blur",
          },
        ],
        // classic: [
        //   {
        //     validator: (rule, value, callback) => {
        //       if (!this.datas.classic) {
        //         callback(new Error(`请填写类别名称`));
        //         return;
        //       }
        //       if (this.datas.classic.trim().length < 1) {
        //         callback(new Error(`请填写类别名称`));
        //         return;
        //       }
        //       callback();
        //     },
        //     trigger: "blur",
        //   },
        // ],
      };
    },
  },
};
</script>
<style lang="scss" scoped>
</style>